import Vue from 'vue'

import Vuex from 'vuex'
Vue.use(Vuex)

const store = new Vuex.Store({
    state: {
        count: 100,

    },
    mutations: {
        addCount(state, value) {
            state.count += value
        },
        subCount(state, value) {
            state.count -= value
        },
        setCount(state, value) {
            state.count = value
        }
    },
    actions: {
        asyncAddCount(store) {
            setTimeout(() => {
                store.commit('addCount', 1)
            }, 2000)
        },
        asyncSubCount(store, value) {
            setTimeout(() => {
                store.commit('subCount', value)
            }, 2000)
        }
    }
})

export default store